package inputWindow;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileManager {

	
	File createFile(String filename) throws IOException
	{
		File newFile;
		newFile = new File(filename);
		if(!newFile.exists())
		{
			newFile.createNewFile();
		}
		
		return newFile;
	
	}
	
	void copyToFile(File filename, String code) throws IOException
	{
		File open = filename;
		FileWriter fstream = new FileWriter(open);
		BufferedWriter out = new BufferedWriter(fstream);
		
		out.write(code);
		out.close();		
	}

	String copyFromFile(File filename) throws IOException
	{
		String theCode;
		String theCode2 = "";
		File open = filename;
		FileInputStream fstream = new FileInputStream(open);
		DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			while((theCode = br.readLine()) != null)
			{
				theCode2 = theCode2 + theCode + "\n"; 
			}
		in.close();
		return theCode2;
	}
	

}
